import NProgress from 'nprogress'
import { hasPower } from '@/utils/powerRoute'

export default (context) => {
  console.log('middleware 全局路由中间件')
  const { store, route, redirect } = context

  const token = store.state.user.token
  const toPath = route.path
  if (hasPower(toPath) && !token) {
    // 关闭进度条
    NProgress.done()
    redirect('/')
  }
}
